Skip to content

fix: check sparse-array holes in the isArrayOf type guard - #455

Merged
gjbkz merged 3 commits into
mainfrom
claude/project-thread-g0uou0-450
Oct 11, 2026
Merged

gjbkz merged 3 commits into
mainfrom
claude/project-thread-g0uou0-450

Conversation

@gjbkz

@gjbkz gjbkz commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Requested by Kei · project thread

Before: isArrayOf(isString)(new Array(1)) returned true, narrowing a sparse array to string[], while validate() and validateAll() rejected the same input at path [0].

After: holes are checked as undefined on every path, so the guard, test(), validate() and validateAll() agree. A hole fails isArrayOf(isString) and passes isArrayOf(isOptionalOf(isString)).

How: the boolean path now uses Array.prototype.findIndex(), which visits holes as undefined, instead of every(), which skips them. An earlier explicit index loop pushed the minified UUID bundle over the 5916-byte budget in test/package.test.ts (5924 bytes) once #453 and #454 were merged; with findIndex() it is 5877 bytes. Tests cover empty, fully sparse, mixed, explicit-undefined and dense arrays against both checkers; the test fails on main and passes here.

Closes #450

🤖 Generated with Claude Code

https://claude.ai/code/session_019BJENnU8SXcDH2Tcx5EWE4

The boolean path used Array.prototype.every(), which skips holes, while
validate() and validateAll() visit every index. The guard now visits
every index too, so a hole is checked as undefined on all paths.

Closes #450

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019BJENnU8SXcDH2Tcx5EWE4
@gjbkz gjbkz self-assigned this Oct 10, 2026
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.46%. Comparing base (bcc1d53) to head (bba1742).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #455   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files          52       52           
  Lines        3055     3057    +2     
  Branches      327      327           
=======================================
+ Hits         3008     3010    +2     
  Misses         46       46           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gjbkz
gjbkz marked this pull request as ready for review October 10, 2026 20:33

@gjbkz gjbkz left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 43904af416b277c018477dd4e4af80d33f85cd2c. No actionable issues found in this change.

Visiting each array index aligns the boolean guard with diagnostic traversal: holes are checked as undefined. The regression coverage checks empty, fully sparse, mixed, explicit-undefined, and dense arrays with both string and optional-string element checkers across the boolean, test(), validate(), and validateAll() paths.

Validation: the complete source unit-test suite passed locally on this reviewed version, and the GitHub Actions test workflow for this commit completed successfully. The latest head is unchanged from the locally tested version.

@gjbkz
gjbkz enabled auto-merge October 11, 2026 07:10
After merging main, the explicit index loop pushed the minified UUID
checker bundle to 5924 bytes, over the 5916-byte budget enforced by
test/package.test.ts. findIndex() also visits holes as undefined, and
keeps the bundle at 5877 bytes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019BJENnU8SXcDH2Tcx5EWE4
@gjbkz
gjbkz merged commit 1ead0f5 into main Oct 11, 2026
7 of 8 checks passed
@gjbkz
gjbkz deleted the claude/project-thread-g0uou0-450 branch October 11, 2026 07:14
@gjbkz gjbkz mentioned this pull request Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

bug: align sparse-array validation between isArrayOf and structured validation

2 participants